package com.zhiwang.planet.mvvm.viewmodel.my

import android.view.View
import androidx.core.widget.ContentLoadingProgressBar
import androidx.databinding.BindingAdapter
import androidx.databinding.ObservableField
import androidx.lifecycle.*
import androidx.paging.PagedList
import com.zhiwang.planet.mvvm.viewmodel.withdraw.Listing
import com.zhiwang.planet.ui.my.record.CommonItemData
import javax.inject.Inject


open class BaseListViewModel : ViewModel() {


    val emptyHint = ObservableField<Boolean>()

//    val refreshing = ObservableField<Boolean>()
//
//    val loadingMore = ObservableField<Boolean>()


}

class DiamondDetailViewModel @Inject constructor(repo: DiamondDetailRepository) : BaseListViewModel() {


    val result: LiveData<Listing<CommonItemData>> = MutableLiveData(repo.listingSource())

    val refreshState = result.switchMap { it.refreshing }.map { it == PagedList.LoadState.DONE }

    val loadMoreState = result.switchMap { it.loadingMoreState }.map { it == PagedList.LoadState.DONE }

    val initProgressVisibility = result.switchMap { it.initLoadDone }.map { if (it) View.GONE else View.VISIBLE }

    val err = result.switchMap { it.err }

    val datas = result.switchMap { it.pagedList }

    fun hide(v: ContentLoadingProgressBar) {
        v.hide()
    }

}


class EnergyDetailViewModel @Inject constructor(repo: BeanDetailRepository) : BaseListViewModel() {


    val result: LiveData<Listing<CommonItemData>> = MutableLiveData(repo.listingSource())

    val refreshState = result.switchMap { it.refreshing }.map { it == PagedList.LoadState.DONE }

    val loadMoreState = result.switchMap { it.loadingMoreState }.map { it == PagedList.LoadState.DONE }

    val err = result.switchMap { it.err }

    val datas = result.switchMap { it.pagedList }

}
